﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using MvcLibrary.Repository;
using System.IO;
using WebVideo.Areas.Admin.Models;

namespace WebVideo.Areas.Admin.Controllers
{
    public class TypeVideoController : Controller
    {
        //
        // GET: /Admin/TypeVideo/

        public ActionResult Index()
        {
            return View(TypeVideoModel.LayDuLieu ());
        }
        #region "Insert"
        public ActionResult Insert()
        {
            TypeVideoModel tnew = new TypeVideoModel();
            return View(tnew);
        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Insert(TypeVideoModel Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    TypeVideoModel.Insert(Mtnew);
                    return RedirectToAction("Index", "TypeVideo");
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //insert


        #region "Edit"
        public ActionResult Edit(int IdTypeVideo)
        {


            return View(TypeVideoModel.LayModel(IdTypeVideo));

        }

        [ValidateInput(false)]
        [HttpPost]
        public ActionResult Edit(TypeVideoModel Mtnew)
        {

            try
            {
                if (ModelState.IsValid)
                {
                    TypeVideoModel.Edit(Mtnew);
                    return RedirectToAction("Index", "TypeVideo");
                }
            }
            catch
            {

                return RedirectToAction("Index", "Error", new { errorMsg = "Lỗi SQL hosting / server" });
            }
            return View(Mtnew);
        }
        #endregion //Edit

        #region "Delete"

        public string Delete(int Id)
        {
            try
            {
                TypeVideoModel.Delete(Id);
                return "ok";

            }
            catch
            {
                return "error";

            }

        }

        #endregion //Delete
    }
}
